<?php
include("include/config.inc.php");
$totalJama  = 0;
$totalUdhar = 0;
$displayJama = 0;
$displayUdhar = 0;
 
  $i=0;             
	$partyArray = array();
  $selectParty = "SELECT party.partyId,party.partyName,party.mobile1,city.city
                    FROM party
                    JOIN city ON city.cityId = party.cityId";
  $selectPartyRes = mysql_query($selectParty);
  $i=0;
  while($partyRow = mysql_fetch_array($selectPartyRes))
  {
    $partyArray[$i]['jamaRupiya'] = 0;              
    $partyArray[$i]['udhaarRupiya'] = 0;
    $select="SELECT transaction.partyId,jamaRupiya,udhaarRupiya
  	           FROM transaction
  	           WHERE partyId=".$partyRow['partyId'];
    $res = mysql_query($select); 
    while($row = mysql_fetch_array($res)) 	
    {           
    	$partyArray[$i]['jamaRupiya']   += $row['jamaRupiya'];
    	$partyArray[$i]['udhaarRupiya'] += $row['udhaarRupiya'];
    }
  	$partyArray[$i]['partyId']       = $partyRow['partyId'];
  	$partyArray[$i]['partyName']     = $partyRow['partyName'];
  	$partyArray[$i]['mobile1']       = $partyRow['mobile1'];
  	$partyArray[$i]['city']          = $partyRow['city'];
  	$partyArray[$i]['totalJama']     = $partyArray[$i]['jamaRupiya'] - $partyArray[$i]['udhaarRupiya'];
  	$partyArray[$i]['totalUdhar']    = $partyArray[$i]['udhaarRupiya'] - $partyArray[$i]['jamaRupiya'];
  	$i++;
  }
//  $displayJama  = $totalJama - $totalUdhar; 
//  $displayUdhar = $totalUdhar - $totalJama; 

$smarty->assign('partyArray',$partyArray);
//$smarty->assign('displayJama',$displayJama);
//$smarty->assign('displayUdhar',$displayUdhar);
$smarty->assign('totalJama',$totalJama);
$smarty->assign('totalUdhar',$totalUdhar);
$smarty->display('allDataAj.tpl');
?>
